﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using migradorWPF.Base; 

namespace migradorWPF.Services
{
    public class MySQLService : BDService
    {
        #region members
        private MySqlConnection _conn;
        private string _typeDb;
        private String _host;
        private string _port;
        private string _nombreDb;
        private string _userDb;
        private string _passUserDb;
        #endregion

        #region properties
        public MySqlConnection Conn
        {
            get { return _conn; }
            set { _conn = value; }
        }

        override public string TypeDb
        {
            get { return _typeDb; }
            set { _typeDb = value; }
        }

        override public String Host
        {
            get { return _host; }
            set { _host = value; }
        }

        override public string Port
        {
            get { return _port; }
            set { _port = value; }
        }

        override public string NombreDb
        {
            get { return _nombreDb; }
            set { _nombreDb = value; }
        }

        override public string UserDb
        {
            get { return _userDb; }
            set { _userDb = value; }
        }

        override public string PassUserDb
        {
            get { return _passUserDb; }
            set { _passUserDb = value; }
        }
        #endregion

        override public bool Conectar()
        {
            try
            {
                this.Conn = new MySqlConnection(String.Format(getConectionString(), this.Host, this.Port, this.NombreDb, this.UserDb, this.PassUserDb));
                this.Conn.Open();
                if (this.Conn.State.Equals(ConnectionState.Open))
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
            return false;
        }

        private string getConectionString()
        {
            return Constantes.StringDeConeccion.Mysql5x;
        }

        override public bool Desconectar()
        {
            try
            {
                this.Conn.Close();
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
    }
}
